package cz.semjobKB.gui;

import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Table;
import cz.semjobKB.virtuoso.document.api.IDocumentDetail;
import cz.semjobKB.virtuoso.document.api.ITerminologyDetail;
import cz.semjobKB.virtuoso.document.api.ITripleDbItem;

import javax.annotation.PostConstruct;

/**
 * Displays list of terminologies and triples in a table
 */
public class TripleTerminologyInfo extends HorizontalSplitPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@SuppressWarnings("restriction")
	@PostConstruct
    protected void init() {
		
	}
	
	@SuppressWarnings("unchecked")
	protected ComponentContainer setDetails(IDocumentDetail docDetail) {
		
		this.setSplitPosition(60);
		this.setLocked(true);
		Table triplesList = new Table();
		Table terminologyList = new Table();
		
		triplesList.addContainerProperty("Subject", String.class,  null);
		triplesList.addContainerProperty("Predicate", String.class,  null);
		triplesList.addContainerProperty("Object", String.class, null);
		
		terminologyList.addContainerProperty("Terminology", String.class,  null);
		terminologyList.addContainerProperty("Frequency", Integer.class,  null);
		terminologyList.addContainerProperty("Relevance", Double.class,  null);
		
		for(ITripleDbItem resourceDetail : docDetail.getTriples()) {
			Object id = triplesList.addItem();
			triplesList.getContainerProperty(id,"Subject").setValue(resourceDetail.getSubject().getResourceLemma()); 
			triplesList.getContainerProperty(id,"Predicate").setValue(resourceDetail.getPredicate().getResourceLemma());
			triplesList.getContainerProperty(id,"Object").setValue(resourceDetail.getObject().getResourceLemma());
		}
		for(ITerminologyDetail resourceDetail : docDetail.getTerminology()) {
			Object id = terminologyList.addItem();
			terminologyList.getContainerProperty(id, "Terminology").setValue(resourceDetail.getResourceLemma());
			terminologyList.getContainerProperty(id, "Frequency").setValue(resourceDetail.getFrequency());
			terminologyList.getContainerProperty(id, "Relevance").setValue(resourceDetail.getRelevance());
		}
		triplesList.setSizeFull();
		terminologyList.setSizeFull();
		this.addComponent(triplesList);
		this.addComponent(terminologyList);
		this.setSizeFull();
		return this;
	}
}
